﻿Imports MySql.Data.MySqlClient

Public Class frmadd_shipper
    Dim mySqlCommand As New MySqlCommand
    Dim mySqlAdaptor As New MySqlDataAdapter
    Dim mySqlReader As MySqlDataReader
    Dim respone As Object
    Dim mysql As MySqlConnection = main_form.mysqlconection
    Private Sub frmadd_shipper_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.CreateSpecificCulture("en-EN")

        mysql.Close()
        If mysql.State = ConnectionState.Closed Then
            mysql.Open()
        End If
    End Sub

    Private Sub ButtonX1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ButtonX1.Click
        System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.CreateSpecificCulture("en-US")
        System.Threading.Thread.CurrentThread.CurrentUICulture = System.Threading.Thread.CurrentThread.CurrentCulture
        mySqlCommand = New MySqlCommand
        If mysql.State = ConnectionState.Closed Then
            mysql.Open()
        End If
        respone = MsgBox("ยืนยันข้อมูลถูกต้อง", MsgBoxStyle.OkCancel + MsgBoxStyle.Information, "Warning Messsage")
        If respone = 1 Then
            Try
                mySqlCommand.Parameters.Clear()
                mySqlCommand.CommandText = "insert into ykp_db.SHIPPER (SHIPNAME,SHIPNICKNAME, SHIPADD, SHIPTELL, SHIPFAX) values (@shipname,@shipnickname,@SHIP_ADD,@SHIP_TELL,@SHIP_FAX)"
                mySqlCommand.Connection = mysql


                mySqlCommand.Parameters.AddWithValue("@shipname", txtcustomer.Text)
                mySqlCommand.Parameters.AddWithValue("@shipnickname", txt_nickname.Text)
                mySqlCommand.Parameters.AddWithValue("@SHIP_ADD", txtcustomer_address.Text)
                mySqlCommand.Parameters.AddWithValue("@SHIP_TELL", txtcustomer_tel.Text)
                mySqlCommand.Parameters.AddWithValue("@SHIP_FAX", txtcustomer_fax.Text)

                mySqlCommand.ExecuteNonQuery()
                mysql.Close()
                txtcustomer.Text = ""
                txt_nickname.Text = ""
                txtcustomer_address.Text = ""
                txtcustomer_fax.Text = ""
                txtcustomer_tel.Text = ""
                MsgBox("Save Complete")
            Catch ex As Exception
                MsgBox(ex.ToString)
            End Try
        End If
        mysql.Close()
    End Sub
    Sub ChangFocus(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtcustomer.KeyPress, txtcustomer_address.KeyPress, txt_nickname.KeyPress
        If e.KeyChar = Microsoft.VisualBasic.ChrW(13) Then
            SendKeys.Send("{TAB}")
            e.Handled = True
        End If
    End Sub
End Class